#region

using System;
using System.ComponentModel.DataAnnotations;
using ThuySan.Bussiness;

#endregion

namespace ThuySan.Models
{
    [Serializable]
    public partial class ProductModel
    {
        #region Constructor

        public ProductModel()
        {
        }

        public ProductModel(Product value)
        {
            ProductId = value.ProductId;
            CategoryId = value.CategoryId;
            Name = value.Name;
            Description = value.Description;
            Detail = value.Detail;
            PromotionalPrice = value.PromotionalPrice;
            Price = value.Price;
            PageUrl = value.PageUrl;
            Priority = value.Priority;
            Viewer = value.Viewer;
            AvatarImage = value.AvatarImage;
            Status = value.Status ?? false;
            IsReduced = value.IsReduced ?? false;
            IsVisibled = value.IsVisibled ?? false;
            LastModified = value.LastModified;
        }

        #endregion

        #region Fields

        private String _AvatarImage;

        private Int32? _CategoryId;

        private String _Description;

        private String _Detail;

        private Boolean _IsReduced;

        private Boolean _IsVisibled;

        private DateTime? _LastModified;

        private String _Name;

        private String _PageUrl;

        private Int32? _Price;

        private Int32? _Priority;

        private Int32 _ProductId;

        private Int32? _PromotionalPrice;

        private Boolean _Status;

        private Int32? _Viewer;

        #endregion

        #region Properties

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public Int32 ProductId
        {
            get { return _ProductId; }
            set { _ProductId = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public Int32? CategoryId
        {
            get { return _CategoryId; }
            set { _CategoryId = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public String Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public String Description
        {
            get { return _Description; }
            set { _Description = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public String Detail
        {
            get { return _Detail; }
            set { _Detail = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public Int32? PromotionalPrice
        {
            get { return _PromotionalPrice; }
            set { _PromotionalPrice = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public Int32? Price
        {
            get { return _Price; }
            set { _Price = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public String PageUrl
        {
            get { return _PageUrl; }
            set { _PageUrl = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public Int32? Priority
        {
            get { return _Priority; }
            set { _Priority = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public Int32? Viewer
        {
            get { return _Viewer; }
            set { _Viewer = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        [StringLength(200, ErrorMessage = "Value must be under 200 characters")]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
            public String AvatarImage
        {
            get { return _AvatarImage; }
            set { _AvatarImage = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public Boolean Status
        {
            get { return _Status; }
            set { _Status = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public Boolean IsReduced
        {
            get { return _IsReduced; }
            set { _IsReduced = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public Boolean IsVisibled
        {
            get { return _IsVisibled; }
            set { _IsVisibled = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public DateTime? LastModified
        {
            get { return _LastModified; }
            set { _LastModified = value; }
        }

        #endregion

        #region Operators

        public void Update(Product value)
        {
            //value.ProductId = ProductId;
            value.CategoryId = CategoryId;
            value.Name = Name;
            value.Description = Description;
            value.Detail = Detail;
            value.PromotionalPrice = PromotionalPrice;
            value.Price = Price;
            value.PageUrl = PageUrl;
            value.Priority = Priority;
            value.Viewer = Viewer;
            //value.AvatarImage = AvatarImage;
            value.Status = Status;
            value.IsReduced = IsReduced;
            value.IsVisibled = IsVisibled;
            value.LastModified = LastModified;
        }

        public static implicit operator ProductModel(Product obj)
        {
            return new ProductModel(obj);
        }

        public static implicit operator Product(ProductModel obj)
        {
            Product value = new Product();
            obj.Update(value);
            return value;
        }

        #endregion
    }
}
